local skel = fk.CreateSkill {
  name = "emo__youya",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__youya"] = "优雅",
  [":emo__youya"] = "锁定技，当你使用一张非虚拟牌时，你记录此牌点数，然后你可以弃置点数之和为记录点数的牌，若如此做，你视为使用一张无距离次数限制的【杀】。",

  ["@emo__youya"] = "优雅",
  ["emo__youya_discard"] = "优雅",
  ["#emo__youya-discard"] = "优雅：你可以弃置点数之和为 %arg 的牌，视为使用【杀】",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and not data.card:isVirtual() and data.card.number > 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local num = data.card.number
    room:setPlayerMark(player, "@emo__youya", num)
    if player.dead or player:isNude() then return end
    local _ , dat = room:askToUseActiveSkill(player, {
      skill_name = "emo__youya_discard", prompt = "#emo__youya-discard:::"..num, extra_data = { emo__youya_num = num }
    })
    if dat then
      room:throwCard(dat.cards, skel.name, player, player)
      if player.dead then return end
      room:askToUseVirtualCard(player, {
        name = "slash", skill_name = skel.name, cancelable = false, extra_data = { bypass_distances = true, bypass_times = true },
      })
    end
  end,
})

local skel2 = fk.CreateSkill {
  name = "emo__youya_discard",
}

skel2:addEffect("active", {
  target_filter = Util.FalseFunc,
  card_filter = function (self, player, to_select, selected)
    local num = self.emo__youya_num or 0
    local sum = 0
    for _, id in ipairs(selected) do
      sum = sum + Fk:getCardById(id).number
    end
    return Fk:getCardById(to_select).number + sum <= num
  end,
  feasible = function (self, player, selected, cards, card)
    if #cards == 0 then return false end
    local num = self.emo__youya_num or 0
    local sum = 0
    for _, id in ipairs(cards) do
      sum = sum + Fk:getCardById(id).number
    end
    return sum == num
  end,
})



return {skel, skel2}
